package com.mvc.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import com.mvc.bean.BaseBean;

public class FullBean {
	
	public FullBean() {
	}
	
	
	public static BaseBean full(String className,HttpServletRequest request) throws Exception{
		Class<?>  cla=Class.forName(className);
		BaseBean bean=(BaseBean)cla.newInstance();
		Field[] filelds= cla.getDeclaredFields();
		for(Field each:filelds){
			each.setAccessible(true);
			String type=each.getType().toString();
			String val=request.getParameter(each.getName());
			if (type.endsWith("int")|| type.endsWith("Integer")) { 
	        	if(val!=null && !"".equals(val)){
	        		each.set(bean,Integer.parseInt(val));
	        	}else{
	        		each.set(bean,0);
	        	}
	        }else{
	        	each.set(bean,val);
	        }
			each.setAccessible(false);
		}
		return bean;
	}

}
